package com.shop.event;

import java.io.Serializable;

import org.hibernate.EmptyInterceptor;
import org.hibernate.Transaction;
import org.hibernate.type.Type;

public class MyInterceptor extends EmptyInterceptor {
	private static final long serialVersionUID = 1L;

	@Override
	public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
		for (int i=0 ;i< propertyNames.length;i++) {
			if( propertyNames[i].equals("dname") ){
				state[i]="修改后的dname";
			}
			System.out.println("==state=="+ state[i] );
			System.out.println("==propertyNames=="+ propertyNames[i] );
			System.out.println("==types=="+ types[i] );
		}
		
		
		return super.onSave(entity, id, state, propertyNames, types);
	}
	@Override
	public void beforeTransactionCompletion(Transaction tx) {
		System.out.println("事务即将结束");
		//tx.rollback();//可以回滚事务
	}
	@Override
	public void afterTransactionBegin(Transaction tx) {
		System.out.println("事务即将开始");
	}

	
}
